package com.chinatelecom.ctyun.xstore.vod.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.chinatelecom.ctyun.xstore.vod.demo.client.XstoreVodClient;
import com.ctyun.xstore.vod.transcode.model.CreateExtractFrameRequest;
import com.ctyun.xstore.vod.transcode.model.CreateTranscodeTaskRequest;
import com.ctyun.xstore.vod.transcode.model.QueryTaskProcessRequest;
import com.ctyun.xstore.vod.transcode.model.SearchTranscodeTaskRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/task")
public class TaskDemoController {

	@Autowired
	private XstoreVodClient xstoreVodClient;

	/**
	 * 创建截帧任务
	 *
	 * @param paramObject 创建截帧任务请求的参数,详见CreateExtractFrameRequest
	 * @return 创建截帧任务的结果，详见CreateExtractFrameResponse
	 * @throws IOException 可能会发生 IO 异常。
	 */
	@PostMapping(value = "/extractFrame/create")
	public Object createExtractFrame(@RequestBody JSONObject paramObject) throws IOException {
		CreateExtractFrameRequest request = paramObject.toJavaObject(CreateExtractFrameRequest.class);
		return xstoreVodClient.getTranscodeTaskClient().createExtractFrame(request);
	}

	/**
	 * 创建/批量创建转码任务
	 *
	 * @param paramObject 创建转码任务请求的参数，详见CreateTranscodeTaskRequest
	 * @return 创建转码任务的结果，详见CreateTranscodeTaskResponse
	 * @throws IOException 可能会发生 IO 异常。
	 */
	@PostMapping(value = "/transcode/create")
	public Object createTranscodeTask(@RequestBody JSONObject paramObject) throws IOException {
		CreateTranscodeTaskRequest request = paramObject.toJavaObject(CreateTranscodeTaskRequest.class);
		return xstoreVodClient.getTranscodeTaskClient().createTranscodeTask(request);
	}

	/**
	 * 查询转码任务状态
	 *
	 * @param paramObject 查询转码任务状态请求的参数，QueryTaskProcessRequest
	 * @return 创建转码任务的结果，QueryTaskProcessResponse
	 * @throws IOException 可能会发生 IO 异常。
	 */
	@PostMapping(value = "/process/qury")
	public Object queryTaskProcess(@RequestBody JSONObject paramObject) throws IOException {
		QueryTaskProcessRequest request = paramObject.toJavaObject(QueryTaskProcessRequest.class);
		return xstoreVodClient.getTranscodeTaskClient().queryTaskProcess(request);
	}

	/**
	 * 搜索转码任务
	 *
	 * @param paramObject 查询转码任务状态请求的参数，SearchTranscodeTaskRequest
	 * @return 创建转码任务的结果，SearchTranscodeTaskResponse
	 * @throws IOException 可能会发生 IO 异常。
	 */
	@PostMapping(value = "/search")
	public Object searchTranscodeTask(@RequestBody JSONObject paramObject) throws IOException {
		SearchTranscodeTaskRequest request = paramObject.toJavaObject(SearchTranscodeTaskRequest.class);
		return xstoreVodClient.getTranscodeTaskClient().searchTranscodeTask(request);
	}
}
